<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="westh.cl.access.pojo.Menu"%>
<%@ page import="westh.cl.access.bo.MenuBO"%>
<%!
int menuId = 0;
String dtreeMenus = "";
void createMenu(MenuBO mbo, int parent){ 
  if (mbo == null) {
    return;
  }
  Menu m = mbo.getMenu();
  if (m.getTitle().equals("----")) {return;}
  menuId++;
  int localMenuId = menuId;
  List submenus = mbo.getMenuList();
  if (submenus == null) {
    dtreeMenus += "d.add(" + menuId + "," + parent +",'" + m.getTitle() + "','" + m.getUrl() + "','" + m.getTitle() + "','mainFrame');\n";
  } else {
    if (submenus.size()==0) {
      dtreeMenus += "d.add(" + menuId + "," + parent +",'" + m.getTitle() + "','../" + m.getUrl() + "','" + m.getTitle() + "','mainFrame');\n";
    } else {
      dtreeMenus += "d.add(" + menuId + "," + parent +",'" + m.getTitle() + "','');\n";
      for (int i=0;i<submenus.size();i++) {
          MenuBO mboSub = (MenuBO) submenus.get(i);
          createMenu(mboSub, localMenuId);
      } 
    }
  }
  return;
}
%> 

<%
List menus = (List) request.getSession().getAttribute("mboVisibleList");
%>

<html>
<head>
  <title>Home</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link rel="StyleSheet" href="css/common.css" type="text/css" />
  <link rel="StyleSheet" href="css/dtree.css" type="text/css" />
  <script type="text/javascript" src="include/dtree.js"></script>
</head>

<body>
<table width="30%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
      <table width="100%" border="0" align="left" cellspacing="0">
      <tr>
        <th width="19" height="100%" align="left" valign="top" scope="col" />
        <th width="162" align="left" valign="top" scope="col">
      <div class="dtree">
          <table width="162" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25" valign="top">
              <p><a href="javascript: d.openAll();" class="style3"><font>Unfold</font></a> <font>|</font>
              <a href="javascript: d.closeAll();" class="style3"><font>Fold</font></a>
            </td>
          </tr>
      <tr>
      <td valign="top">
            <script type="text/javascript">
    <!--
    d = new dTree('d');
    d.add(0,-1,'&nbsp;<font>Menu</font></a>');
<% 
  menuId = 0;
  dtreeMenus = "";
  for (int i=0;i<menus.size();i++) {
      MenuBO mbo = (MenuBO) menus.get(i);
      createMenu(mbo, 0);
  }
  menuId = 0;
  out.println(dtreeMenus);
%>              
    document.write(d);
    //-->
        </script>
        </td>
        </tr>
        </table>
       </div>
        </th>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="50"><p align="center">&nbsp;</p>
    </td>
  </tr>
</table>
</body>
</html>
